package org.snail.employee.service.push;

import lombok.extern.log4j.Log4j;
import org.snail.activemq.PushService;
import org.snail.employee.service.message.EmployeesMessageCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;

/**
 * 推送人员相关信息到队列
 */
@Service
@Log4j
@Scope("prototype")
public class EmployeesPushService implements PushService {

    @Autowired
    private JmsTemplate jmsTemplate;

    @Autowired
    @Qualifier("employeesQueue")
    private Destination destination;

    @Override
    public void push(Object sendObject) {
        //创建消息执行者
        EmployeesMessageCreator messageCreator = new EmployeesMessageCreator();
        messageCreator.setSendObject(sendObject);

        log.info("EmployeesMessageCreator : " + messageCreator);

        //推送消息到队列
        jmsTemplate.send(destination, messageCreator);
    }

}

